#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    tcpsocket = new QTcpSocket;

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_open_clicked()
{
    tcpsocket->connectToHost(ui->addr->text(),ui->portID->text().toUInt());
    connect(tcpsocket,SIGNAL(connected()),this,SLOT(connect_slot()));
}

void Widget::connect_slot()
{
    connect(tcpsocket,SIGNAL(readyRead()),this,SLOT(readyRead_slot()));
}

void Widget::readyRead_slot()
{
    QString buf;
    buf = tcpsocket->readAll();
    ui->recv_box->appendPlainText(buf);
}
void Widget::on_close_clicked()
{
    tcpsocket->close();
}

void Widget::on_send_clicked()
{
    tcpsocket->write(ui->send_box->text().toUtf8().data());
}
